package com.ph.controller;

import com.ph.pojo.Permission;
import com.ph.pojo.Result;
import com.ph.pojo.RolePermission;
import com.ph.service.PermissionService;

import org.apache.shiro.authz.annotation.RequiresUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("sys/permission")
public class PermissionController {
    @Autowired
    private PermissionService permissionService;

    @GetMapping("findByRoleId")
    public Result<List<Permission>> findByRoleId(Integer roleId) {
        return Result.success("true",permissionService.permissionTree(roleId));
    }

    @PostMapping("check")
    public Result<Boolean> check(@RequestBody RolePermission rolePermission) {
        return Result.success(permissionService.checkPermission(rolePermission));
    }

    @PostMapping("check/parent")
    public Result<Boolean> checkParent(@RequestBody RolePermission rolePermission) {
        return Result.success(permissionService.checkParentPermission(rolePermission));
    }

    @RequiresUser
    @GetMapping("menu")
    public Result<List<Permission>> menu() {
        return Result.success(permissionService.findLevel1ByUserId());
    }
}
